﻿using System;
using System.Data;
using System.Linq;
using System.Web.UI.WebControls;
using DevelopmentPFR.Utilitaire;

namespace DevelopmentPFR.Centrale_Achat
{
    public partial class CommandesFournisseurs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ListeCommandeCA.DataSource = BaseDeDonnees.ExecuteSelectStoredProcedure("spCa_listeCommandeCa");
            ListeCommandeCA.DataBind();
            foreach (GridViewRow row in ListeCommandeCA.Rows)
            {
                ((HyperLink)row.FindControl("linkToDetailCa")).NavigateUrl = "DetailCommandesFournisseurs.aspx?ref=" + ((HyperLink)row.FindControl("linkToDetailCa")).Text;
            }
        }

        protected void OnRowDataBoundGenerateMultipleLinks(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRow line = ((DataRow) ((DataTable) ListeCommandeCA.DataSource).Rows[e.Row.RowIndex]);
                string linksHyp = (string)line["refCommandeHyp"];
                string[] splitLinks = linksHyp.Split(',');

                for (int i = 0; i < splitLinks.Count(); i++)
                {
                    HyperLink linkToHyp = new HyperLink();
                    linkToHyp.Text = splitLinks[i] + "  ";
                    linkToHyp.NavigateUrl = "DetailCommandesHypermarches.aspx?ref=" + splitLinks[i];
                    e.Row.Cells[1].Controls.Add(linkToHyp);
                }
            }
        }
    }
}